<?php
/**
 * Created by PhpStorm.
 * User: sosyuki
 * Date: 2018/5/15
 * Time: 10:31
 */

namespace Drupal\distribution\ViewsController;


use Drupal\distribution\ViewsController\handler\field\DistributionEditInfoLink;
use Drupal\distribution\ViewsController\handler\field\DistributionFieldChildCount;
use Drupal\distribution\ViewsController\handler\field\DistributionFieldOrderCount;
use Drupal\distribution\ViewsController\handler\field\DistributionFieldValidity;
use Drupal\distribution\ViewsController\handler\filter\ParentDistributionUsers;
use Drupal\distribution\ViewsController\handler\filter\TeamDistributionUsers;
use EntityDefaultViewsController;

class DistributionViewsController extends EntityDefaultViewsController {

  function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $data[$table]['validity'] = [
        'title' => t('绑定有效期'),
        'help' => t('绑定有效期.'),
        'field' => [
          'field' => 'timestamp',
          'handler' => DistributionFieldValidity::class,
        ],
      ];

      $data[$table]['child_count'] = [
        'title' => t("下家数量"),
        'help' => t('下家数量.'),
        'field' => [
          'field' => 'pid',
          'handler' => DistributionFieldChildCount::class,
        ],
      ];
      $data[$table]['order_count'] = [
        'title' => t("成单数量"),
        'help' => t('成单数量.'),
        'field' => [
          'field' => 'uid',
          'handler' => DistributionFieldOrderCount::class,
        ],
      ];

      $data[$table]['edit_distribution'] = [
        'title' => t('编辑关系链接'),
        'help' => t('编辑关系链接.'),
        'field' => [
          'field' => 'id',
          'handler' => DistributionEditInfoLink::class,
        ],
      ];


      $data[$table]['parent_distribution_users'] = [
        'real field' => 'pid',
        'title' => t('上家列表'),
        'help' => t('上家列表'),
        'group' => 'Distribution',
        'filter' => [
          'handler' => ParentDistributionUsers::class,
        ],
      ];

      $data[$table]['team_distribution_users'] = [
        'real field' => 'tid',
        'title' => t('团队列表'),
        'help' => t('团队列表'),
        'group' => 'Distribution',
        'filter' => [
          'handler' => TeamDistributionUsers::class,
        ],
      ];


    }
    return $data;
  }


}
